
*Table 1

matrix D=J(55, 2,.)
gen col =0
log using desc_hara_rr, replace
foreach gen in woman man{
	replace col=col+1
	local col =col
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1 &  age>=18 & age<=35
	matrix  D[1,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1 &  age>=36 & age<=50
	matrix  D[2,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1 &  age>=51 & age<=64
	matrix  D[3,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1 &  age>=65 & age!=.
	matrix  D[4,`col']=r(mean)

	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1 &  fams>=100 & fams<=200 & barn>=1 & barn!=.
	matrix  D[6,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1 &  fams>=100 & fams<=200  & barn==0
	matrix  D[7,`col']=r(mean) 
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1 &  ((fams>=100 & fams<=200) | fams==400)  & barn>=1 & barn!=.
	matrix  D[8,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1 &    ((fams>=100 & fams<=200) | fams==400) & barn==0
	matrix  D[9,`col']=r(mean)

	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1 &  educ_year>= 7 & educ_year<=10
	matrix  D[11,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1 &  educ_year>=11 & educ_year<=13
	matrix  D[12,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  &  educ_year>= 14 & educ_year<=21
	matrix  D[13,`col']=r(mean)

	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & olust==5
	matrix  D[15,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & olust==4
	matrix  D[16,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & olust<4
	matrix  D[17,`col']=r(mean)

	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & formaga==10
	matrix  D[19,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & formaga<10
	matrix  D[20,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & ind_feq==2
	matrix  D[21,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & ind_feq==1
	matrix  D[22,`col']=r(mean)

	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & ssyk1==1
	matrix  D[24,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & ssyk1==2
	matrix  D[25,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & ssyk1==3
	matrix  D[26,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & ssyk1==4
	matrix  D[27,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & ssyk1==5
	matrix  D[28,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & ssyk1==6
	matrix  D[29,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & ssyk1==7
	matrix  D[30,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & ssyk1==8
	matrix  D[31,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & ssyk1==9
	matrix  D[32,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & ssyk1==0
	matrix  D[33,`col']=r(mean)

	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & occw3==1
	matrix  D[35,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & occw3==2
	matrix  D[36,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & occw3==3
	matrix  D[37,`col']=r(mean)

	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & occw3==1
	matrix  D[39,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & occw3==2
	matrix  D[40,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  & occw3==3
	matrix  D[41,`col']=r(mean)

	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  &  workpl_size>=5 &  workpl_size<=10
	matrix  D[43,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  &  workpl_size>=11 &  workpl_size<=25
	matrix  D[44,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  &  workpl_size>=26 &  workpl_size<=100
	matrix  D[45,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  &  workpl_size>=101 &  workpl_size<=500
	matrix  D[46,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  &  workpl_size>=500 &  workpl_size!=.
	matrix  D[47,`col']=r(mean)

	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  &  workpl_m>=0 &  workpl_m<=.1
	matrix  D[49,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  &  workpl_m>.10 &  workpl_m<=.25
	matrix  D[50,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  &  workpl_m>.250 &  workpl_m<=75
	matrix  D[51,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  &  workpl_m>.75 &  workpl_m<=.9
	matrix  D[52,`col']=r(mean)
	sum hara_comb  [aw=gen_edu2_alder5_w ] if main_sample==1 & `gen'==1  &  workpl_m>.9 &  workpl_m<=1
	matrix  D[53,`col']=r(mean)
}
matrix list D
log close
 
*Table A2
log Table_A2
tab year if lopnr!=.
tab year if lopnr!=. & ariyrket!=.
tab year if lopnr!=. & ariyrket!=. & olust!=.
tab year if lopnr!=. & ariyrket!=. & olust!=. & hara_comb!=.
tab year if lopnr!=. & ariyrket!=. & olust!=. & hara_comb!=. & workpl_m>=5 &  workpl_m!=. 
tab year if lopnr!=. & ariyrket!=. & olust!=. & hara_comb!=. & workpl_m>=5 &  workpl_m!=. & ln_wage!=.
log close

*Table A4
destring ssyk3, force gen( ssyk3num)
gen count=1 if main_samp==1 & hara_comb!=.
bysort ssyk3 woman: egen  ssyk3_gensum=sum(count)
foreach yvar in sex_trak hara_comb hara_cust hara_coll{
	bysort ssyk3 woman: egen  ssyk3mean_`yvar'=mean(`yvar') if ssyk3_gensum>=50 & ssyk3_gensum!=. &  main_samp==1 & hara_comb!=.
	bysort  woman: egen  ssyk3rank_`yvar'=rank(ssyk3mean_`yvar') if ssyk3_gensum>=50 & ssyk3_gensum!=. & main_samp==1 & hara_comb!=., field
}

log using hara_occrank, replace
	bysort woman ssyk3rank_hara_comb: sum ssyk3num hara_comb ssyk3_m 
log close

*Table III
gen firm_fe_5_chpos_3 =firm_fe_5_chneg_3==0 &  wpch_ee_d3==1 if firm_fe_5_chneg_3!=. 
gen  man_wp_chpos_3 = man_wp_chneg_3==0 &  wpch_ee_d3==1 if  man_wp_chneg_3!=. 
gen ln_wage_chpos_3 = ln_wage_chneg_3==0 &  wpch_ee_d3==1 if  ln_wage_chneg_3!=. 

reg  man_wp_chneg_3 hara_comb [pw=gen_edu2_alder5_w ] if main==1 & age<60 & woman==1
outreg2 using transition_reg, dec(3) excel replace

reg  man_wp_chneg_3 hara_comb workpl_m [pw=gen_edu2_alder5_w ] if main==1 & age<60 & woman==1
outreg2 using transition_reg, dec(3) excel append

reg  man_wp_chpos_3 hara_comb [pw=gen_edu2_alder5_w ] if main==1 & age<60 & woman==0
outreg2 using transition_reg, dec(3) excel append

reg  man_wp_chpos_3 hara_comb workpl_m [pw=gen_edu2_alder5_w ] if main==1 & age<60 & woman==0
outreg2 using transition_reg, dec(3) excel append

reg  firm_fe_5_chneg_3 hara_comb [pw=gen_edu2_alder5_w ] if main==1 & age<60 & woman==1
outreg2 using transition_reg, dec(3) excel append

reg  firm_fe_5_chneg_3 hara_comb firm_fe_5 [pw=gen_edu2_alder5_w ] if main==1 & age<60 & woman==1
outreg2 using transition_reg, dec(3) excel append

reg  firm_fe_5_chpos_3 hara_comb [pw=gen_edu2_alder5_w ] if main==1 & age<60 & woman==0
outreg2 using transition_reg, dec(3) excel append

reg  firm_fe_5_chpos_3 hara_comb firm_fe_5[pw=gen_edu2_alder5_w ] if main==1 & age<60 & woman==0
outreg2 using transition_reg, dec(3) excel append

*Table IV & Table A7
gen seku_dis=-hara_risk_w*.17 -hara_risk_m*.06 if man==0
replace seku_dis=-hara_risk_w*.06 -hara_risk_m*.17 if man==1
gen seku_dis_w=-hara_risk_w*.17 -hara_risk_m*.06 
gen  seku_dis_m=-hara_risk_w*.06 -hara_risk_m*.17 
gen wp_utility=  seku_dis+firm_fe_5
gen wp_utility_w=seku_dis_w  + firm_fe_5
gen wp_utility_m=seku_dis_m + firm_fe_5
gen wp_utility_w_1=seku_dis_w  + firm_fe_1
gen wp_utility_m_1=seku_dis_m + firm_fe_1
gen wp_utility_w_mfe_1=seku_dis_w  + firm_fe_m1
gen wp_utility_m_mfe_1=seku_dis_m + firm_fe_m1
gen wp_utility_w_wfe_1=seku_dis_w + firm_fe_w1
gen wp_utility_m_wfe_1=seku_dis_m + firm_fe_w1


preserve
keep if main_samp==1 & hara_comb!=. & firm_fe_5!=. & workpl_m!=.

collapse ln_wage   firm_fe_5  hara_risk_w hara_risk_m seku_dis_w seku_dis_m wp_utility_w wp_utility_m  , by (woman)
save back_of_envelope, replace
restore
preserve
keep if main_samp==1 & hara_comb!=. & firm_fe_1!=. & workpl_m!=. & firm_fe_m1!=. & firm_fe_w1!=.

collapse ln_wage firm_fe_1 firm_fe_w1 firm_fe_m1  hara_risk_w hara_risk_m seku_dis_w seku_dis_m   wp_utility_w_wfe_1 wp_utility_m_mfe_1 , by (woman)
gen limited=1
append using back_of_envelope
save back_of_envelope, replace
restore

*Table A3
* Loop to append waves of the work environment survey 
clear
gen drop = .
save "\\micro.intra\Projekt\P0844$\P0844_Gem\Arbetsmiljö\desc_popsamp.dta", replace
 
forvalues year=1999(2)2007{
 
	use "\\micro.intra\projekt\P0844$\P0844_Data\Rickne_Lev_Lisa_`year'.dta", clear
	ren peorgnr_lopnr orgnr
	gen year = `year'
	drop if orgnr==.	
	keep lopnr year syssstat* sun* forvink* civil
	joinby lopnr using "\\micro.intra\Projekt\P0844$\P0844_Data\Rickne_Lev_Bakgrund.dta"
	destring fodelsear, replace force
	gen age = year-fodelsear
	append using "\\micro.intra\Projekt\P0844$\P0844_Gem\Arbetsmiljö\desc_popsamp.dta"
	save "\\micro.intra\Projekt\P0844$\P0844_Gem\Arbetsmiljö\desc_popsamp.dta", replace
}

gen woman=kon=="2"
replace syssstat= syssstatj if syssstat==""
destring sun2000niva, replace
gen educ = floor(sun2000niva/100)
drop sun2000niva
label define educ 1 "No primary education" 2 "Primary education 9 years" 3 "Secondary education" ///
	4 "College/university education < 2 yrs" 5 "College/university education > 2 yrs" ///
	6 "PhD/Research education" 9 "Unknown education"
label values educ educ

gen educ_cat = 0
replace educ_cat = 1 if educ == 1
replace educ_cat = 2 if educ == 2 | educ == 3
replace educ_cat = 3 if educ == 4 | educ == 5 | educ == 6
replace educ_cat = . if educ == 9	
compress educ  educ_cat
joinby lopnr year using "\\micro.intra\Projekt\P0844$\P0844_Gem\Arbetsmiljö\arb_hara.dta", unmatched (master)
	drop hara_comb_ygm hara_comb_reg hara_coll_ygm hara_comp hara_coll_reg hara_ind_mean hara_all _merge
	
foreach var in forvink {
	gen `var'_real= .
	replace `var'_real= `var'/0.990027*1.2596 if year==1999
	replace `var'_real= `var'/1.024549*1.2596  if year==2001
	replace `var'_real= `var'/1.066743*1.2596  if year==2003
	replace `var'_real= `var'/1.075566*1.2596  if year==2005
	replace `var'_real= `var'/1.114346*1.2596  if year==2007
	replace `var'= `var'_real
	drop `var'_real
}
gen ink_bel200= forvink<2000 if forvink!=.
gen ink_bel200_400= forvink>=2000 & forvink<4000 if forvink!=.
gen ink_bel400_400= forvink>=4000 & forvink<64000 if forvink!=.
gen ink_bel2_ab600= forvink>=6000  if forvink!=.
gen never_mar=civil=="OG" if  civil!=""	
gen mar=civil=="G" if  civil!=""	
gen div=civil=="S" if  civil!=""	
gen wid= civil!="S" &  civil!="G" &  civil!="OG" ///
&  civil!="EP" &  civil!="SP" if  civil!=""	
gen lowed= educ ==1 | educ==2 if educ!=. & educ!=9
gen hs= educ ==3 if educ!=.  & educ!=9
gen short_u=  educ ==4  if educ!= . & educ!=9
gen long_u=educ ==5  if educ!=.  & educ!=9
gen phd =educ ==6 | educ==7 if educ!=.  & educ!=9
gen sv= fodelseland_eu15 =="Sverige" if  fodelseland_eu15 !=""
gen nord= fodelseland_eu15 =="Norden utom Sverige"  if fodelseland_eu15 !="Europa utom EU15 och Norden"
gen euro= fodelseland_eu15 =="EU15 utom Norden" &  fodelseland_eu15 =="" if  fodelseland_eu15 !=""
gen non_euro= sv==0 & nord==0 & euro==0 if fodelseland_eu15 !=""
gen age_18_35= age>=18 & age<=36 if age !=.
gen age_36_50 = age>=36 & age<=50
gen age_51_65 =age>=51 & age<=65
log using desc_harasamp, replace
sum ink_bel200-age_51_65 woman age if hara_comb==. & woman==1
sum ink_bel200-age_51_65 woman age if hara_comb!=. & woman==1

log close
joinby lopnr year using "\\micro.intra\Projekt\P0844$\P0844_Gem\Arbetsmiljö\temp hara.dta"
		
keep if hara_comb!=.
log using desc_haraexec, replace
sum ink_bel200-age_51_65 woman age if exec==0 & woman==1
sum ink_bel200-age_51_65 woman age if exec==1 & woman==1
log close

